export default class DebugUtils {
    static _debugTag: number = 1486940

    static _debug: boolean = CC_DEV

    static showBound(node: cc.Node, fill: boolean = true) {
        if (!this._debug) return
        // let chNode = node.getChildByTag(DebugUtils._debugTag)
        //
        // //单独加一个调试节点,用于显示一些额外信息.
        // if (chNode == null) {
        //     chNode = new cc.Node("debugNode")
        //     node.addChild(chNode, 100000, DebugUtils._debugTag)
        // }
        //
        // chNode.width = node.width
        // chNode.height = node.height
        // chNode.setAnchorPoint(node.getAnchorPoint())
        // chNode.setPosition(0, 0)
        let chNode = node
        let g = chNode.getComponent(cc.Graphics)
        if (g == null) {
            g = chNode.addComponent(cc.Graphics)
        }
        g.clear(true)
        g.lineWidth = 2
        g.strokeColor = cc.Color.RED
        g.fillColor = cc.color(0xff, 0, 0, 50)
        let rect = node.getBoundingBox()

        if (fill) {
            g.fillRect(0, 0, rect.width, rect.height)
            g.fill()
        }
        g.circle(chNode.anchorX * chNode.width, chNode.anchorY * chNode.height, 5)
        g.rect(0, 0, rect.width, rect.height)
        g.stroke()

    }

    static clearBound(node: cc.Node) {
        if (!this._debug) return
        let chNode = node.getChildByTag(DebugUtils._debugTag)
        if (chNode != null) {
            chNode.removeComponent(cc.Graphics)
        }
    }
}